# coding = utf-8
# 导入库
from lxml import etree
import requests
# 旧版丁香园 可爬取，新版丁香园不可爬取
url = 'http://www.dxy.cn/bbs/thread/626626#626626'
r = requests.get(url)
r.encoding = 'utf-8'
html = r.text
tree = etree.HTML(html)
user = tree.xpath('//div[@class="auth"]/a/text()')
#print(user)
content = tree.xpath('//td[@class="postbody"]')
results = []
for i in range(0, len(user)):
    # print(user[i].strip()+":"+content[i].xpath('string(.)').strip())
    # print("*"*80)
    # 因为回复内容中有换行等标签，所以需要用string()来获取数据
    results.append(user[i].strip() + ":  " + content[i].xpath('string(.)').strip())

for i, result in zip(range(0, len(user)), results):
    print("user" + str(i+1) + "-" + result)
    print("*"*100)
